/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 * Author: Huawei OS Kernel Lab
 * Create: Thu Aug 15 16:14:23 2023
 */

#ifndef __LIBLINUX_ASM_PREEMPT_H
#define __LIBLINUX_ASM_PREEMPT_H

#define __preempt_count_add	___preempt_count_add
#define __preempt_count_sub	___preempt_count_sub

#include_next <asm-generic/preempt.h>

#undef __preempt_count_add
#undef __preempt_count_sub

static __always_inline void __preempt_count_add(int val)
{
	volatile int *ptr = preempt_count_ptr();
	if (*ptr == 0)
		liblinux_pal_preempt_disable();
	*ptr += val;
}

static __always_inline void __preempt_count_sub(int val)
{
	volatile int *ptr = preempt_count_ptr();
	*ptr -= val;
	if (*ptr == 0)
		liblinux_pal_preempt_enable();
}

#endif /* __LIBLINUX_ASM_PREEMPT_H */
